﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Bass.Tools;
using MySql.Data.MySqlClient;

public partial class admin_add_productkind : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["adminname"]) == "")
        {
            Response.Write("<script language=javascript>alert('您没有登录');window.parent.document.location.href ='admin_login.aspx'</script>");
        }
        else if (Convert.ToString(Session["adminkind"]) != "product")
        {
            Response.Write("<script language=javascript>alert('您不是产品管理员，无权访问此页！');location='admin_login.aspx'</script>");
        }
        if (!IsPostBack)
        {
            
        }
    }

    protected void ClearTextBox()
    {
        productkinden.Text = string.Empty;
        productkind.Text = string.Empty;
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        ClearTextBox();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        //OleDbConnection Conn = new OleDbConnection();
        //Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../miumiu.mdb");
        //Conn.Open();

        //取到连接字符串
        string propertiesPath = Server.MapPath("../mysqldb.properties");
        mytools mt = new mytools();
        string ConnString = mt.getMysqlConn(propertiesPath);

        //打开连接
        MySqlConnection myConnection = new MySqlConnection(ConnString);
        myConnection.Open();
        
        string productkinden1 = productkinden.Text.ToString();
        string productkind1 = productkind.Text.ToString();
        string addadminname1 = Convert.ToString(Session["adminname"]);
        DateTime dt = Convert.ToDateTime(DateTime.Now);
        string addtime1 = dt.ToString("yyyyMMddHHmmss");
        string kindid = addadminname1 + addtime1;
        string sqlinsert = "insert into productkind values" +
                        "('" + kindid + "','" + productkinden1 + "','" + productkind1 + "','" + addadminname1 + "','A','" + addtime1 + "')";
        MySqlCommand scd = new MySqlCommand(sqlinsert, myConnection);
        scd.ExecuteNonQuery();
        Response.Write("<script lanuage=javascript>alert('添加产品类别成功！');location ='add_productkind.aspx'</script>");
        myConnection.Close();

    }    


}
